<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>学生信息录入</legend>
    </fieldset>

    <div class="layui-form-item required">
        <label class="layui-form-label">学号输入框</label>
        <div class="layui-input-inline">
            <input type="text" name="sno"  id="sno"    lay-verify="required|sno" lay-reqtext="学号不能为空" placeholder="请输入学生学号" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名输入框</label>
        <div class="layui-input-inline">
            <input type="text" name="sname" id="sname" lay-verify="required|name" lay-reqtext="姓名不能为空" placeholder="请输入学生姓名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">电话输入框</label>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="tel" name="stel" id="stel"  lay-verify="required|phone" lay-reqtext="电话不能为空" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>





    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-inline">
            <select name="sdid">
                <option value="">-请选择-</option>
                <option value="21001" selected="">后勤部门</option>
                <option value="21002">文体部门</option>
                <option value="21003">生活部门</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职称</label>
        <div class="layui-input-inline">
            <select name="sjob">
                <option value="">-请选择-</option>
                <option value="干事" selected="">干事</option>
                <option value="副部长">副部长</option>
                <option value="部长">部长</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</div>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 2) {
                    return '姓名至少得2个字符啊';
                }
            }
            , sno: [
                /^[\S]{6,12}$/
                , '学号必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            var index=layer.msg("数据添加中，请稍后....",{
                icon:16,
                time:1000,
                shade:0.8
            },function(){

                var url="/addStudent/"
                $.post(url,data.field,function (result){
                    if( result.code == 200 ){
                        layer.close(index);
                        alert(result.message);
                        // layer.alert(JSON.stringify(data.message));
                        //  data= {"elem":{},"field":{"sno":"153107182892","sname":"String key","stel":"15310718285","sdid":"21010","sjob":"部长"}}
                        // layer.alert(JSON.stringify(result.message));
                        // result ={"code":200,"message":"增添成功了！"}
                        // layer.closeAll("iframe")
                        parent.location.reload();
                    }else {
                        //添加失败
                        layer.alert(JSON.stringify(result.message));
                    }

                })

            });



            return false;
        });

    });
</script>
</body>
</html>